package com.lanou.zhihu.web.controller;

import com.lanou.zhihu.entity.User;
import com.lanou.zhihu.service.AnswerGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by QuChao on 2018/10/31.
 */
@Controller
@RequestMapping("answerGood")
public class AnswerGoodController {
    @Autowired
    private AnswerGoodService answerGoodService;

    @ResponseBody
    @RequestMapping("/findByUidAid")
    public boolean findByUidAid(HttpServletRequest request, Integer aid) {
        User user = (User) request.getSession().getAttribute("user");
        return answerGoodService.findByUidAid(user, aid);
    }

    @ResponseBody
    @RequestMapping("/good")
    public boolean good(Integer aid, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return answerGoodService.good(user, aid);
    }

    @ResponseBody
    @RequestMapping("/cancelGood")
    public boolean cancelGood(Integer aid, HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        return answerGoodService.cancelGood(user, aid);
    }

    @ResponseBody
    @RequestMapping("/selectCount")
    public Integer selectCount(Integer aid){
        return answerGoodService.selectCount(aid);
    }
}
